package pers.lance.mvcrest.plus.plus.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.lance.mvcrest.plus.plus.pojo.Book;
import pers.lance.mvcrest.plus.plus.service.BookService;

import java.util.List;

/**
 * @ Author     ：LILA3
 * @ Date       ：Created in 5:26 PM 7/25/2018
 */
@RestController
@RequestMapping(value = "/books")
public class BookController {
    @Autowired
    private BookService bookService;

    private static String SUCCESS = "success";
    private static String FAIL = "fail";

    @GetMapping("/list")
    @ResponseBody
    public List<Book> list() {
        return bookService.findAll();
    }

    @PostMapping("/add")
    @ResponseBody
    public Book add(@RequestBody Book book) {
        return bookService.addBook(book);
    }

    @PostMapping("/delete")
    @ResponseBody
    public Book delete(@RequestBody Book book) {
        return bookService.deleteBook(book);
    }

    @PostMapping("/update")
    @ResponseBody
    public Book update(@RequestBody Book book) {
        return bookService.updateBook(book);
    }
}

